<template>
	<div class="main_box" style="padding:10px">
		<el-card class="add-wrapper">
			<el-tabs v-model="module">
				<el-tab-pane label="提现设置" name="first">
					<el-form  :model="dataForm.cashInfo" ref="dataForm" :rules="roleRules" class="el-form__one" label-width="130px">
						<el-row>
							<el-form-item label="用户类型" prop="userType">
								<el-radio v-model="dataForm.cashInfo.userType" :label="1">企业商户</el-radio>
								<el-radio v-model="dataForm.cashInfo.userType" :label="2">个体工商户</el-radio>
							</el-form-item>

							<el-form-item label="提现方式" prop="cashType">
								<el-radio v-model="dataForm.cashInfo.cashType" :label="1">提现至自有账户</el-radio>
								<el-radio v-model="dataForm.cashInfo.cashType" :label="2">提现至上级账户</el-radio>
							</el-form-item>
							<el-form-item label="结算方式" prop="settleType">
								<el-radio v-model="dataForm.cashInfo.settleType" :label="1">每日结算</el-radio>
								<el-radio v-model="dataForm.cashInfo.settleType" :label="2">每月结算</el-radio>
							</el-form-item>
							<el-form-item label="结算日" prop="settleDay" v-show="dataForm.cashInfo.settleType==2">
								<el-input v-maxnum="{ obj: dataForm.cashInfo, key: 'settleDay', int: true,max:28 }" placeholder="取值1~28" v-model="dataForm.cashInfo.settleDay" >
									<span slot="suffix">号</span>
								</el-input>
							</el-form-item>
							<el-form-item label="提现天数" prop="cashDay">
								<div class="flex" style="display:flex">
									<div>
										T+
									</div>
									<el-input class="flex-input" v-model="dataForm.cashInfo.cashDay"
										@input="handleInput('cashDay')">
									</el-input>
									<div>
										天
									</div>
								</div>
							</el-form-item>
						</el-row>
					</el-form>
					<div class="btn-wrapper" style="border-bottom: 1px solid rgb(218, 215, 215);padding-bottom: 10px;">
						<el-button plain type="primary" @click="saveCashInfo">保 存</el-button>
						<el-button plain @click="returnList">取 消</el-button>
					</div>
				</el-tab-pane>
				<el-tab-pane label="实名认证" name="second">
					<el-form :model="dataForm.qualityAccount"  ref="dataForm2" :rules="roleRules2"  class="el-form__two"
						label-width="130px">
						<el-row>
							<el-form-item label="企业名称" prop="businessName">
								<el-input v-model="dataForm.qualityAccount.businessName"></el-input>
							</el-form-item>
							<el-form-item label="企业联系人姓名" prop="linkName">
								<el-input v-model="dataForm.qualityAccount.linkName"></el-input>
							</el-form-item>
							<el-form-item label="企业联系人电话" prop="linkPhone">
								<el-input v-model="dataForm.qualityAccount.linkPhone"  v-maxnum="{obj:dataForm.qualityAccount,key:'linkPhone',zero:true,int:true}"></el-input>
							</el-form-item>
							<el-form-item label="真实姓名(法人)" prop="fullName">
								<el-input v-model="dataForm.qualityAccount.fullName"></el-input>
							</el-form-item>
							<el-form-item label="手机号" prop="phone">
								<el-input type="number" v-model="dataForm.qualityAccount.phone" v-maxnum="{obj:dataForm.qualityAccount,key:'phone',zero:true,int:true}"></el-input>
							</el-form-item>
							<el-form-item label="身份证号" prop="idCard">
								<el-input v-model="dataForm.qualityAccount.idCard"></el-input>
							</el-form-item>
						</el-row>
						<el-row>
							<el-form-item prop="businessLicense" label="营业执照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 10 }"
									folder="user/account/img">
									<img v-if="dataForm.qualityAccount.businessLicense" width="100%" :src="dataForm.qualityAccount.businessLicense"
										alt="">
									<div class="tip" v-if="!dataForm.qualityAccount.businessLicense">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item prop="idCardFront" label="身份证正面照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 11 }" folder="user/account/img">
									<img v-if="dataForm.qualityAccount.idCardFront" width="100%"
										:src="dataForm.qualityAccount.idCardFront" alt="">
									<div class="tip" v-if="!dataForm.qualityAccount.idCardFront">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item prop="idCardBack" label="身份证反面照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 12 }" folder="user/account/img">
									<img v-if="dataForm.qualityAccount.idCardBack" width="100%"
										:src="dataForm.qualityAccount.idCardBack" alt="">
									<div class="tip" v-if="!dataForm.qualityAccount.idCardBack">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
						</el-row>
					</el-form>
					<div class="btn-wrapper">
						<el-button plain type="primary" @click="saveBusinessAccount">保 存</el-button>
						<el-button plain @click="returnList">取 消</el-button>
					</div>
				</el-tab-pane>
				<el-tab-pane label="企业账户" name="third">
					<el-form :model="dataForm.company" ref="dataForm3" :rules="roleRules3" class="el-form__two"
						label-width="130px">
						<el-row>
							<el-form-item label="企业名称" prop="businessName">
								<el-input v-model="dataForm.company.businessName" clearable>

								</el-input>
							</el-form-item>
							<el-form-item label="企业联系人姓名" prop="linkName">
								<el-input v-model="dataForm.company.linkName"></el-input>
							</el-form-item>
							<el-form-item label="企业联系人电话" prop="linkPhone">
								<el-input v-model="dataForm.company.linkPhone"
									v-maxnum="{ obj: dataForm.company, key: 'linkPhone', zero: true, int: true }"></el-input>
							</el-form-item>
							<el-form-item label="真实姓名(法人)" prop="fullName">
								<el-input v-model="dataForm.company.fullName"></el-input>
							</el-form-item>
							<el-form-item label="手机号" prop="phone">
								<el-input type="number" v-model="dataForm.company.phone"
									:readonly="dataForm.company.ymAccountId ? true : false"
									v-maxnum="{ obj: dataForm.company, key: 'phone', zero: true, int: true }">
									<el-button v-if="!dataForm.company.ymAccountId" type="success" slot="append"
										@click="getYmAccountInfo(1)">
										获取信息
									</el-button>
								</el-input>
							</el-form-item>
							<el-form-item label="身份证号" prop="idCard">
								<el-input v-model="dataForm.company.idCard"></el-input>
							</el-form-item>
							<el-form-item label="银行卡类型" prop="cardType">
								<el-radio-group v-model="dataForm.company.cardType">
									<el-radio :label="1">公有账户</el-radio>
									<el-radio :label="2">私有法人</el-radio>
								</el-radio-group>
							</el-form-item>
							<el-form-item label="银行" prop="bankCode">
								<el-select v-model="dataForm.company.bankCode" clearable filterable
									@change="handleBankChange(1)">
									<el-option v-for="item in bankList" :value="item.bankCode" :label="item.bankName"
										:key="item.code"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="银行支行" prop="branchCode">
								<el-input v-model="dataForm.company.branchName" clearable @focus="getBranchBankList(1)"
									placeholder="选择银行支行"></el-input>
							</el-form-item>
							<el-form-item label="银行卡号" prop="cardNo">
								<el-input v-model="dataForm.company.cardNo"
									v-maxnum="{ obj: dataForm.company, key: 'cardNo', zero: true, int: true }">

								</el-input>
							</el-form-item>
							<el-form-item label="设为结算账户" prop="defaultFlag">
								<el-radio-group v-model="dataForm.company.defaultFlag"
									:disabled="dataForm.company.ymAccountId ? true : false">
									<el-radio :label="0">
										否
									</el-radio>
									<el-radio :label="1">
										是
									</el-radio>
								</el-radio-group>
							</el-form-item>
							<el-form-item label="开通状态" v-if="dataForm.company.ymAccountId">
								<el-tag size="samll" effect="dark" :type="formatOpenStates(dataForm.company.openState)">
									{{ formatOpenState(dataForm.company.openState) }}
								</el-tag>
							</el-form-item>
							<el-form-item label="启用状态" v-if="dataForm.company.ymAccountId">
								<el-tag size="samll" effect="dark" :type="dataForm.company.relationState?'':'danger'">
									{{ dataForm.company.relationState?'启用':'禁用' }}
								</el-tag>
							</el-form-item>
						</el-row>
						<el-row>
							<el-form-item prop="businessLicense" label="营业执照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 1 }"
									folder="user/account/img">
									<img v-if="dataForm.company.businessLicense" width="100%"
										:src="dataForm.company.businessLicense" alt="">
									<div class="tip" v-if="!dataForm.company.businessLicense">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item prop="idCardFront" label="身份证正面照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 2 }"
									folder="user/account/img">
									<img v-if="dataForm.company.idCardFront" width="100%"
										:src="dataForm.company.idCardFront" alt="">
									<div class="tip" v-if="!dataForm.company.idCardFront">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item prop="idCardBack" label="身份证反面照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 3 }"
									folder="user/account/img">
									<img v-if="dataForm.company.idCardBack" width="100%" :src="dataForm.company.idCardBack"
										alt="">
									<div class="tip" v-if="!dataForm.company.idCardBack">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item label="银行卡正面照:" prop="bankCardFront" v-show="dataForm.company.cardType == 2">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 4 }"
									folder="user/account/img">
									<img v-if="dataForm.company.bankCardFront" width="100%"
										:src="dataForm.company.bankCardFront" alt="">
									<div class="tip" v-if="!dataForm.company.bankCardFront">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item label="银行卡反面照:" prop="bankCardBack" v-show="dataForm.company.cardType == 2">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 5 }"
									folder="user/account/img">
									<img v-if="dataForm.company.bankCardBack" width="100%"
										:src="dataForm.company.bankCardBack" alt="">
									<div class="tip" v-if="!dataForm.company.bankCardBack">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
						</el-row>

					</el-form>
					<div class="btn-wrapper" size="small">
						<el-button plain type="primary" @click="sureClick(1)">
							保 存
						</el-button>
						<el-button plain @click="returnList">取 消</el-button>
					</div>
				</el-tab-pane>
				<el-tab-pane label="个人账户" name="fourth">
					<el-form :model="dataForm.person" :rules="roleRules4" ref="dataForm4" label-width="160px"
						class="el-form__two">
						<el-row>
							<el-form-item label="真实姓名" prop="fullName">
								<el-input v-model="dataForm.person.fullName"></el-input>
							</el-form-item>
							<el-form-item label="手机号" prop="phone">
								<el-input type="number" v-model="dataForm.person.phone"
									:readonly="dataForm.person.ymAccountId ? true : false"
									v-maxnum="{ obj: dataForm.person, key: 'phone', zero: true, int: true }">
									<el-button v-if="!dataForm.person.ymAccountId" type="success" slot="append"
										@click="getYmAccountInfo(3)">
										获取信息
									</el-button>
								</el-input>
							</el-form-item>
							<el-form-item label="身份证号" prop="idCard">
								<el-input v-model="dataForm.person.idCard"></el-input>
							</el-form-item>
							<el-form-item label="持卡人姓名" prop="cardName">
								<el-input v-model="dataForm.person.cardName">

								</el-input>
							</el-form-item>
							<el-form-item label="银行" prop="bankCode">
								<el-select v-model="dataForm.person.bankCode" clearable filterable
									@change="handleBankChange(2)">
									<el-option v-for="item in bankList" :value="item.bankCode" :label="item.bankName"
										:key="item.code"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="银行支行" prop="branchCode">
								<el-input v-model="dataForm.person.branchName" clearable @focus="getBranchBankList(2)"
									placeholder="选择银行支行"></el-input>
							</el-form-item>
							<el-form-item label="银行卡号" prop="cardNo">
								<el-input v-model="dataForm.person.cardNo"
									v-maxnum="{ obj: dataForm.person, key: 'cardNo', zero: true, int: true }">

								</el-input>
							</el-form-item>

							<el-form-item label="设为结算账户" prop="defaultFlag">
								<el-radio-group v-model="dataForm.person.defaultFlag"
									:disabled="dataForm.person.ymAccountId ? true : false">
									<el-radio :label="0">
										否
									</el-radio>
									<el-radio :label="1">
										是
									</el-radio>
								</el-radio-group>
							</el-form-item>
							<el-form-item label="开通状态" v-if="dataForm.person.ymAccountId">
								<el-tag size="samll" effect="dark" :type="formatOpenStates(dataForm.person.openState)">
									{{ formatOpenState(dataForm.person.openState) }}
								</el-tag>
							</el-form-item>
							<el-form-item label="启用状态" v-if="dataForm.person.ymAccountId">
								<el-tag size="samll" effect="dark" :type="dataForm.person.relationState?'':'danger'">
									{{ dataForm.person.relationState?'启用':'禁用' }}
								</el-tag>
							</el-form-item>
						</el-row>
						<el-row>
							<el-form-item prop="idCardFront" label="身份证正面照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 6 }"
									folder="user/account/img">
									<img v-if="dataForm.person.idCardFront" width="100%" :src="dataForm.person.idCardFront"
										alt="">
									<div class="tip" v-if="!dataForm.person.idCardFront">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item prop="idCardBack" label="身份证反面照:">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 7 }"
									folder="user/account/img">
									<img v-if="dataForm.person.idCardBack" width="100%" :src="dataForm.person.idCardBack"
										alt="">
									<div class="tip" v-if="!dataForm.person.idCardBack">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item label="银行卡正面照:" prop="bankCardFront">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 8 }"
									folder="user/account/img">
									<img v-if="dataForm.person.bankCardFront" width="100%"
										:src="dataForm.person.bankCardFront" alt="">
									<div class="tip" v-if="!dataForm.person.bankCardFront">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
							<el-form-item label="银行卡反面照:" prop="bankCardBack">
								<upload-img class="upload-img" @uploadFileList="getImgUrl" :param="{ type: 9 }"
									folder="user/account/img">
									<img v-if="dataForm.person.bankCardBack" width="100%"
										:src="dataForm.person.bankCardBack" alt="">
									<div class="tip" v-if="!dataForm.person.bankCardBack">
										<i class="el-icon-upload"></i>
										<div class="el-upload__text">将图片拖到此处，或<em>点击上传</em>
										</div>
									</div>
								</upload-img>
							</el-form-item>
						</el-row>
					</el-form>
					<div class="btn-wrapper" size="small">
						<el-button plain type="primary" @click="sureClick(2)">
							保 存
						</el-button>
						<el-button plain @click="returnList">取 消</el-button>
					</div>
				</el-tab-pane>
			</el-tabs>
		</el-card>
		<el-dialog title="银行支行" :visible.sync="branchBank.show" center width="fit-content" destory-on-close>
			<el-form class="search_wrap" :inline="true" :model="branchBank" ref="searchForm">
				<el-form-item prop="branchName">
					<el-input v-model="branchBank.branchName" clearable placeholder="支行名称"></el-input>
				</el-form-item>
				<el-form-item prop="branchCode">
					<el-input v-model="branchBank.branchCode" clearable placeholder="支行编号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button icon="el-icon-search" type="primary" size="mini" @click="searchBranchList">查询</el-button>
					<el-button icon="el-icon-refresh-left" size="mini" @click="resetForm">重置</el-button>
				</el-form-item>
			</el-form>
			<el-table :data="branchBankList" highlight-current-row @current-change="handleCurrentClick" max-height="600">
				<el-table-column type="index" label="序号" align="center" width="100">

				</el-table-column>
				<el-table-column prop="branchName" label="支行名称" align="center" width="270">

				</el-table-column>
				<el-table-column prop="branchCode" label="支行编号" align="center" width="230">

				</el-table-column>
			</el-table>
			<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="page.pageNo" :page-sizes="[20, 50, 100]" :page-size="page.pageSize"
				layout="total, sizes, jumper, next, pager, prev" :total="page.pageTotal"></el-pagination>
			<!-- <div slot="footer">
				<el-button type="primary">
					确定
				</el-button>
				<el-button>
					取消
				</el-button>
			</div> -->
		</el-dialog>

	</div>
</template>

<script>
import * as message from "@/constants/message";
import BusinessApi from '@/api/business/business';
import YmAccountApi from '@/api/account/ymAccount';
import AccountInfoApi from '@/api/account/accountInfo';
import { getStorage } from '@/utils/auth'
import { USER_INFO } from "@/constants/storeName"
import UploadImg from "@/components/UploadImg"

export default {
	data() {
		return {
			list: [
			],
			module: "first",
			dataForm: {
				businessId: "",
				company: {
					// ymAccountId:"",
					userType: "",
					fullName: "",
					phone: "",
					idCard: "",
					idCardFront: "",
					idCardBack: "",
					businessName: "",
					businessLicense: "",
					linkName: "",
					linkPhone: "",
					cardType: 1,
					cardNo: "",
					bankCode: "",
					branchCode: "",
					bankName: "",
					branchName: "",
					bankCardFront: "",
					bankCardBack: "",
					defaultFlag: "",
					openState: "",
					relationState: "",
				},
				person: {
					// ymAccountId:"",
					userType: 3,
					fullName: "",
					phone: "",
					idCard: "",
					idCardFront: "",
					idCardBack: "",
					cardType: 2,
					cardNo: "",
					bankCode: "",
					bankName: "",
					branchName: "",
					branchCode: "",
					bankCardFront: "",
					bankCardBack: "",
					defaultFlag: "",
					openState: "",
					relationState: "",
				},
				cashInfo:{
					cashDay:'',
					cashType:1,
					settleDay:"",
					settleType:1,//1.每日结算 2. 每月结算
					userType:1,

				},
				qualityAccount:{
					accountInfoId:"",
					userType: 1,
					fullName: "",
					phone: "",
					idCard: "",
					idCardFront: "",
					idCardBack: "",
					businessName: "",
					businessLicense: "",
					linkName: "",
					linkPhone: "",
				}

			},
			page: {
				pageNo: 1,
				pageTotal: 0,
				pageSize: 20
			},
			defaultFlags: ["", ""], //这里在获取数据的时候保存初始的是否设置为结算卡的状态
			bankList: [],
			branchBankList: [],
			branchBank: {
				show: false,
				type: "",
				branchCode: "",
				branchName: "",
			},
			roleRules:{
				userType: [
					{ required: true, message: "请选择用户类型", trigger: "change" }
				],
				cashType: [
					{ required: true, message: "请选择提现方式", trigger: "change" }
				],
				settleType: [
					{ required: true, message: "请选择结算方式", trigger: "change" }
				],
				cashDay:[
					{ required: true, message: "请输入提现天数", trigger: "blur" }
				],
			},
			roleRules2:{
				businessName: [
					{ required: true, message: "请填写企业名称", trigger: "blur" }
				],
				fullName: [
					{ required: true, message: "请输入真实姓名", trigger: "blur" }
				],
				phone: [
					{ required: true, message: "请输入手机号", trigger: "blur" },
					{ pattern: /(^1(3|4|5|6|7|8|9)\d{9}$)|(^0\d{2,3}-?\d{7,8}$)/, message: "手机号格式错误", trigger: "blur" },
				],
				idCard: [
					{ required: true, message: "请输入身份证号", trigger: "blur" },
					{ pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: "身份证式错误", trigger: "blur" },
				],
				linkName: [
					{ required: true, message: "请输入企业联系人姓名", trigger: "blur" },
				],
				linkPhone: [
					{ required: true, message: "请输入企业联系人电话", trigger: "blur" },
					{ pattern:  /^400[0-9]{7}|^1[345789]\d{9}$|^0[0-9]{2,3}-[0-9]{8}/, message: "电话格式错误", trigger: "blur" },
				],
				businessLicense: [
					{ required: true, message: "请上传一张营业执照", trigger: "change" },
				],
			},
			roleRules3: {
				businessName: [
					{ required: true, message: "请填写企业名称", trigger: "blur" }
				],
				cardType: [
					{ required: true, message: "请选择账户类型", trigger: "change" }
				],
				linkName: [
					{ required: true, message: "请输入企业联系人姓名", trigger: "blur" },
				],
				linkPhone: [
					{ required: true, message: "请输入企业联系人电话", trigger: "blur" },
					{ pattern: /^400[0-9]{7}|^1[345789]\d{9}$|^0[0-9]{2,3}-[0-9]{8}/, message: "电话格式错误", trigger: "blur" },
				],
				businessLicense: [
					{ required: true, message: "请上传一张营业执照", trigger: "change" },
				],
			},
			roleRules4: {
				cardName: [
					{ required: true, message: "请填写持卡人姓名", trigger: "blur" }
				],
			},
			commonRules: {
				fullName: [
					{ required: true, message: "请输入真实姓名", trigger: "blur" }
				],
				phone: [
					{ required: true, message: "请输入手机号", trigger: "blur" },
					{ pattern: /(^1(3|4|5|6|7|8|9)\d{9}$)|(^0\d{2,3}-?\d{7,8}$)/, message: "手机号格式错误", trigger: "blur" },
				],
				idCard: [
					{ required: true, message: "请输入身份证号", trigger: "blur" },
					{ pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: "身份证式错误", trigger: "blur" },
				],
				idCardFront: [
					{ required: true, message: "请上传身份证正面照", trigger: "change" }
				],
				idCardBack: [
					{ required: true, message: "请上传身份证反面照", trigger: "change" }
				],
				cardNo: [
					{ required: true, message: "请填银行卡号", trigger: "blur" }
				],
				bankCode: [
					{ required: true, message: "请选择银行", trigger: "change" }
				],
				branchCode: [
					{ required: true, message: "请选择银行支行", trigger: "change" }
				],
				bankCardFront: [
					{ required: true, message: "请上传银行卡正面照", trigger: "change" }
				],
				bankCardBack: [
					{ required: true, message: "请上传银行卡反面照", trigger: "change" }
				],
				defaultFlag: [
					{ required: true, message: "请选择是否设为结算账户", trigger: "change" },
				],
			}
		}
	},
	watch: {
		"dataForm.company.cardType": {
			handler(val) {
				const { roleRules3, commonRules } = this
				this.$nextTick(() => {
					this.$refs.dataForm3.clearValidate()
				})
				if (val == 1) {
					delete roleRules3.bankCardFront
					delete roleRules3.bankCardBack
				} else {
					this.roleRules3 = { ...roleRules3, ...commonRules }
				}
			},
		},
		"dataForm.cashInfo.settleType":{
			handler(val){
				const {roleRules} = this
				if(val==2){
					this.$set(roleRules,'settleDay',[{ required: true, message: "请输入结算日", trigger: "blur" }])
				}else{
					this.$delete(roleRules,'settleDay')
				}
				this.$nextTick(()=>{
					if(this.$refs.dataForm){
						this.$refs.dataForm.clearValidate()
					}

				})
			},
			immediate:true
		},
	},
	components: {
		UploadImg,
	},
	mounted() {
		this.init()
	},
	methods: {
		async init() {
			const { dataForm } = this
			dataForm.businessId = this.$route.query.id
			await this.getData()
			this.getBankList()
			this.modifyRules()
			// this.getUserType()
		},
		async getData() {
			const { dataForm, defaultFlags } = this
			const {businessId,cashInfo} = dataForm
			let res = await YmAccountApi.getBusinessAccountInfo({ businessId })
			const res2 = await AccountInfoApi.getAccountInfo({ businessId })
			const {cashDay,cashType,settleType,settleDay,userType} = res2.data
			cashInfo.cashDay = cashDay
			cashInfo.cashType = cashType||2
			cashInfo.settleDay = settleDay
			cashInfo.settleType = settleType
			cashInfo.userType = userType
			dataForm.qualityAccount = res2.data
			res = res.data || []
			res.forEach(item => {
				if (item.userType == 3) {
					defaultFlags[1] = item.defaultFlag
					dataForm.person = item
				} else {
					defaultFlags[0] = item.defaultFlag
					dataForm.company = item
				}
			})

		},
		// async getUserType() {
		// 	const { company, businessId } = this.dataForm
		// 	const res = await AccountInfoApi.getAccountInfo({ businessId })
		// 	company.userType = res.data.userType
		// },
		async getYmAccountInfo(type) {
			const { dataForm } = this
			const form = type == 1 ? 'dataForm3' : 'dataForm4'
			this.$refs[form].validateField("phone", async (err) => {
				if (!err) {
					await this.$confirm("确定获取并使用翼码信息", "提示", {})
					const { company, person } = this.dataForm
					const params = {
						userType: type,
						phone: type == 1 ? company.phone : person.phone
					}
					const {data} = await YmAccountApi.getDataByNameType(params)
					if (data) {
						delete data.businessId
						type == 1 ? dataForm.company = data : dataForm.person = data
					}else{
						this.$message.error("暂无可用的翼码信息")
					}

					this.$nextTick(() => {
						this.$refs[form].clearValidate()
					})
					// this.$Utils.bindingBean(type==1?dataForm.company:dataForm.person, res2.data)
				}
			})
		},
		formatOpenStates(val) {
			switch (val) {
				case 1:
					return ""
				case 2:
					return "success"
				case 3:
					return "danger"
			}
		},
		formatOpenState(val) {
			switch (val) {
				case 1:
					return "开户审核中"
				case 2:
					return "开户成功"
				case 3:
					return "开户失败"
			}
		},
		// 修改检验规则
		modifyRules() {
			let { roleRules3, roleRules4, commonRules, dataForm: { company, person } } = this
			let temp = null

			temp = { ...commonRules }
			if (company.cardType == 1) {
				delete temp.bankCardBack
				delete temp.bankCardFront
			}
			if (company.ymAccountId) {
				delete temp.defaultFlag
				this.roleRules3 = {
					...roleRules3, ...temp
				}
			} else {
				this.roleRules3 = {
					...roleRules3, ...temp
				}
			}
			if (person.ymAccountId) {
				temp = { ...commonRules }
				delete temp.defaultFlag
				this.roleRules3 = {
					...roleRules3, ...temp
				}
			} else {
				this.roleRules4 = {
					...roleRules4, ...commonRules
				}
			}
			this.$nextTick(() => {
				this.$refs.dataForm3.clearValidate()
				this.$refs.dataForm4.clearValidate()
			})
		},
		// 获取商户Logo路径
		getImgUrl(val) {
			if (val.uploadFileList.length > 0) {
				this.$Utils.notifySuccess("上传成功");
				const { person, company,qualityAccount } = this.dataForm
				const url = val.uploadFileList[0]
				const { type } = val.param
				switch (type) {
					case 1:
						company.businessLicense = url
						break
					case 2:
						company.idCardFront = url
						break
					case 3:
						company.idCardBack = url
						break
					case 4:
						company.bankCardFront = url
						break
					case 5:
						company.bankCardBack = url
						break
					case 6:
						person.idCardFront = url
						break
					case 7:
						person.idCardBack = url
						break
					case 8:
						person.bankCardFront = url
						break
					case 9:
						person.bankCardBack = url
						break
					case 10:
						qualityAccount.businessLicense = url
						break
					case 11:
						qualityAccount.idCardFront = url
						break
					case 12:
						qualityAccount.idCardBack = url
						break
				}
			}

		},
		handleInput(prop) {
			const { dataForm } = this
			switch (prop) {
				case 'cashDay':
					dataForm.cashInfo.cashDay = dataForm.cashInfo.cashDay.replace(/([^\d]*)|(^0$)/g, "")
					break

			}
		},
		// 提现信息保存
		async saveCashInfo(){
			const { cashInfo,businessId,qualityAccount:{accountInfoId} } = this.dataForm
			await this.$refs.dataForm.validate()
			await this.$confirm("确定保存提现信息？","提示",{})
			const params = Object.assign({ ...cashInfo }, { businessId })
			if(params.settleType==1){
				delete params.settleDay
			}
			if(accountInfoId){
				params.accountInfoId = accountInfoId
			}
			AccountInfoApi.setAccountBase(params).then(res => {
				this.$Utils.notifySuccess("设置成功")
			})
		},
		// 账户信息保存
		async saveBusinessAccount() {
			const { qualityAccount,businessId } = this.dataForm
			await this.$refs.dataForm2.validate()
			await this.$confirm("确定保存账户信息？","提示",{})
			const params = Object.assign({ ...qualityAccount }, { businessId })
			if(params.settleType==1){
				delete params.settleDay
			}
			AccountInfoApi.setAccountInfo(params).then(res => {
				this.$Utils.notifySuccess("设置成功")
			})
		},
		// 获取银行卡列表
		getBankList() {
			BusinessApi.listBankCode().then(res => {
				this.bankList = res.data
			})
		},
		// 点击获取银行卡支行的列表
		async getBranchBankList(type) {
			const { dataForm: { company, person }, branchBank, page } = this
			const { pageSize, pageNo } = page
			branchBank.type = type
			const bankCode = type == 1 ? company.bankCode : person.bankCode
			if (bankCode) {
				const params = {
					pageSize,
					pageNo,
					bankCode,
					branchCode: branchBank.branchCode,
					branchName: branchBank.branchName
				}
				const res = await BusinessApi.pageBranchCode(params)
				const { list, total } = res.data
				this.branchBankList = list || []
				page.pageTotal = total
				branchBank.show = true
			} else {
				this.$message.error("请先选择银行")
			}
		},
		// 搜索支行
		searchBranchList() {
			const { page, branchBank: { type } } = this
			page.pageNo = 1
			this.getBranchBankList(type)
		},
		resetForm() {
			this.$refs.searchForm.resetFields()
		},
		handleSizeChange(size) {
			this.page.pageSize = size
			this.getBranchBankList(this.branchBank.type)

		},
		handleCurrentChange(val) {
			this.page.pageNo = val
			this.getBranchBankList(this.branchBank.type)
		},
		// 选中支行
		handleCurrentClick(val) {
			if (!val) return
			const { dataForm: { company, person }, branchBank } = this
			const { branchCode, branchName } = val
			if (branchBank.type == 1) {
				company.branchCode = branchCode
				company.branchName = branchName
			} else {
				person.branchCode = branchCode
				person.branchName = branchName
			}
			branchBank.show = false
		},
		// 银行改变
		handleBankChange(type) {
			const { bankList, dataForm: { company, person } } = this
			let val = null
			switch (type) {
				case 1:
					if (company.bankCode) {
						company.bankName = bankList.find(item => item.bankCode==company.bankCode).bankName
					} else {
						company.bankName = ""
					}
					company.branchName = ""
					company.branchCode = ""
					break
				case 2:
					if (person.bankCode) {
						person.bankName = bankList.find(item => item.bankCode==person.bankCode).bankName
					} else {
						person.bankName = ""
					}
					person.branchName = ""
					person.branchCode = ""
					break
			}
		},
		checkData(type) {
			const { defaultFlags, dataForm: { company, person } } = this
			if (type == 1 && !company.ymAccountId && !company.defaultFlag && !defaultFlags[1]) {
				this.$message.error("保存该账户需要设置为结算账户")
				return false
			} else if (type == 2 && !company.ymAccountId && !person.defaultFlag && !defaultFlags[0]) {
				this.$message.error("保存该账户需要设置为结算账户")
				return false
			}
			return true
		},
		async sureClick(type) {
			let valid = null
			if (type == 1) {
				valid = await this.$refs.dataForm3.validate()
			} else {
				valid = await this.$refs.dataForm4.validate()
			}
			if (!valid) return
			const { company, person, businessId,cashInfo } = this.dataForm
			if(type==1&&!cashInfo.userType){
				this.$message.error("请在设置中选择用户类型")
				return
			}else{
				company.userType = cashInfo.userType
			}
			if (!this.checkData(type)) return
			this.$confirm(message.MSG_CONFIRM_SAVE_ALTER, message.TITLE_PROMPT, {})
				.then(() => {

					let params = Object.assign({}, { businessId })
					params = type == 1 ? Object.assign(params, company, { cardName: company.businessName }) : Object.assign(params, person)
					this.saveInfo(params)
				});
		},
		async saveInfo(params) {
			if (params.ymAccountId) delete params.defaultFlag
			await YmAccountApi.setYmAccount(params)
			this.$Utils.notifySuccess()
		},
		returnList() {
			this.$store.dispatch('delView', this.$route);
			this.$router.back();
		}
	},

}
</script>
<style lang="scss" scoped>
@import "@/assets/css/views/add.scss";
</style>
<style lang="scss" scoped>
@import "@/assets/css/views/addType.scss";
</style>
<style lang="scss" scoped>
.upload-img {
	&::v-deep .el-upload {
		width: 100% !important;

		.el-upload-dragger {
			width: 100%;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.tip {
				padding-bottom: 30px;
			}
		}
	}
}

.flex {

	// width: 300px;
	.flex-input {
		// width:240px;
		margin: 0 10px !important;

		&::v-deep .el-input__inner {
			width: 100% !important;
		}
	}
}
</style>
